package com.huizluo.module1;

import java.util.Random;

//双色球 摇奖
public class DoubleBall {
    private int[] redBall;
    private int[] blueBall;

    public DoubleBall() {
        this.redBall = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};
        this.blueBall = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    }


    public static void main(String[] args) {
        DoubleBall db = new DoubleBall();
        int[] red = new int[6];
        Random r = new Random(System.nanoTime());
        for (int i=0;i<6;i++){
            int rt = r.nextInt(32);//去一个随机数
            int shotNum = db.redBall[rt];//用随机数做下标读取红球数组中的数值
            if (shotNum == 0){//如果当前下标的数值已经被取走了，则设置为0，重新执行一次随机取数
                i--;
                continue;
            }else{
                red[i] = shotNum;//取到的数组放入结果集中
                db.redBall[rt] = 0;//设置被取走位置的数值为0，防止再次取到
            }
        }

        int blueIndex = r.nextInt(14);
        int blueNum = db.blueBall[blueIndex];

        System.out.println("red ball is:");
        for (int i=0;i<6;i++){
            if (i == 5){
                System.out.println(red[i]);
            }else{
                System.out.print(red[i] + ",");
            }

        }
        System.out.println("blue ball is:");
        System.out.println(blueNum);
    }
}
